<template>
  <div class="wrapper" ref="wrapper">
    <div class="content2">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BScroll from "better-scroll";

export default {
  props: {
    probeType: {
      type: Number,
      default: 0,
    },
    pullUpLoad: {
      type: Boolean,
      default: false,
    },
  },

  data() {
    return {
      scroll: null,
    };
  },

  mounted() {
    //   创建BScroll对象
    this.scroll = new BScroll(this.$refs.wrapper, {
      // 是否点击
      click: true,
      // 滚动判断
      probeType: this.probeType,
      // 触底判断
      pullUpLoad: this.pullUpLoad,
    });

    // 监听滚动
    if (this.probeType == 2 || this.probeType == 3) {
      this.scroll.on("scroll", (positon) => {
        this.$emit("scroll", positon);
      });
    }

    // 监听触底
    if (this.pullUpLoad) {
      this.scroll.on("pullingUp", () => {
        this.$emit("pullingUp");
      });
    }
  },

  methods: {
    // 触底事件
    finishPullUP() {
      this.scroll && this.scroll.finishPullUp();
    },

    // 刷新事件
    refresh() {
      this.scroll && this.scroll.refresh();
      console.log("---");
    },
  },

  // 到达位置事件
  scrollTo(a, b, c = 300) {
    this.scroll && this.scroll.scrollTo(a, b, c);
  },

  // 判断滚动位置
  getScrollY() {
    return this.scroll ? this.scroll.y : 0;
  },
};
</script>

<style scoped></style>
